/**
 * createRouter 这个为创建路由的方法
 * createWebHashHistory 这个就是vue2中路由的模式，
 *                      这里的是hash模式，这个还可以是createWebHistory等
 * RouteRecordRaw 这个为要添加的路由记录，也可以说是routes的ts类型
 */
import { createRouter, createWebHashHistory } from "vue-router";
import NProgress from "nprogress";
import {routes} from "~/router/routes";

const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      path: "/login",
      component: () => import("~/views/login/index.vue"),
      meta: { title: "登录" },
    }, {
      path: "/",
      redirect: "/home",
      component: () => import("@/layouts/Layouts.vue"),
      children: [
        ...routes,
        {
          path: "/home",
          component: () => import("@/views/Home.vue"),
          meta: { title: "首页" },
        }, {
          path: "/system/company-list",
          component: () => import("@/views/config/companyList/List.vue"),
          meta: { title: "公司列表" },
        }, {
          path: "/system/company",
          component: () => import("@/views/system/company/List.vue"),
          meta: { title: "公司" },
        }, {
          path: "/system/org",
          component: () => import("@/views/system/org/List.vue"),
          meta: { title: "组织机构" },
        }, {
          path: "/system/role",
          component: () => import("@/views/system/role/List.vue"),
          meta: { title: "角色" },
        }, {
          path: "/system/user",
          component: () => import("@/views/system/user/List.vue"),
          meta: { title: "系统用户" },
        }, {
          path: "/system/article",
          component: () => import("~/views/system/article/List.vue"),
          meta: { title: "文章管理" },
        }, {
          path: "/system/user-info",
          component: () => import("~/views/system/user/info/Index.vue"),
          meta: { title: "个人中心" },
        }, {
          path: "/system/menu",
          component: () => import("~/views/config/menu/List.vue"),
          meta: { title: "角色" },
        }, {
          path: "/system/dictionary",
          component: () => import("~/views/config/dictionary/List.vue"),
          meta: { title: "字典" },
        }, {
          path: "/system/message",
          component: () => import("~/views/config/message/List.vue"),
          meta: { title: "消息" },
        }, {
          path: "/system/log",
          component: () => import("~/views/config/log/Index.vue"),
          meta: { title: "日志" },
        }, {
          path: "/system/gen-table",
          component: () => import("~/views/config/gen/List.vue"),
          meta: { title: "代码生成" },
        }, {
          path: "/wechat/user",
          component: () => import("~/views/wechat/user/List.vue"),
          meta: { title: "微信用户" },
        }, {
          path: "/wechat/original",
          component: () => import("~/views/wechat/original/List.vue"),
          meta: { title: "微信注册表" },
        },
      ],
    },
  ],
});


router.beforeEach((to, from, next) => {
  NProgress.start(); // 进度条开始
  next();
  if (to.meta.title) {
    // @ts-ignore
    document.title = to.meta.title;
  }
});

router.afterEach(() => {
  NProgress.done(); // 进度条结束
});

export default router;
